import static java.lang.System.*
import static java.util.Date.*
import static javax.swing.JOptionPane.*

textArea.with{
    def selection = selection[0].clone()
    def isEndEnter = (selectedText[-1] =~ /\n\s*$/)
    def oldtext = selectedText
    def newtext = selectedText.replaceAll(/(?m)[ 　\t]+$/, "")
    selectedText = newtext + (isEndEnter?"\n":"")
	addToSelection(new org.gjt.sp.jedit.textarea.Selection.Range(selection.start, selection.end + newtext.size() - oldtext.size()))
}
